<?php

use Illuminate\Support\Facades\Route;

/*
 * @Description: 
 * @version: 
 * @Author: FCesky
 * @Date: 2020-11-30 10:24:37
 * @LastEditors: FCesky
 * @LastEditTime: 2020-11-30 14:47:25
 */

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//---------------------------单一路由----------------------------------------------------------------
//return一个视图模板，如果是静态网站，可以不用到控制器，静态页面全部走路由就可以了
Route::get('/', function () {
    return view('welcome');
});
Route::get('index', function () {
    return view('index');
});
Route::get('/dashboard', function () {
    return view('dashboard');
});
//return一个字符串
Route::get('/hello', function () {
    return 'hello laravel!';
});
//return一个控制器的方法
Route::get('/say','TestController@say');
Route::get('form','RequestController@formPage');
Route::post('form/file_upload','RequestController@fileUpload');
Route::post('form', 'RequestController@form')->name('form.submit');
//路由传参
Route::get('user/{id}',function($id){
    return 'user id:'.$id;
});
//路由传参（可选）,需要定义默认值
Route::get('param/{id?}',function($id=1){
    return 'user id:'.$id;
});
//路由命名
//推荐：前段调用<a href="{{route('user.name',['name'=>'asdad'])}}"></a>，就算路由改变，也不用改变前端代码，做到前端和路由的解耦
Route::get('name/{name?}',function($name='fcesky'){
    return 'user name is:'.$name;
})->name('user.name');
//-------------------------------------------一组路由---------------------------------------------------
//路由分组
//一组路由共用一个中间件
Route::middleware('mymiddleware')->group(function(){
    Route::get('action1',function(){
        return 1;
    });
    Route::get('action2',function(){
        return 2;
    });
});
//一组路由公用多个中间件
Route::middleware(['mymiddleware1','mymiddleware2'])->group(function(){
    Route::get('action1',function(){
        return 1;
    });
    Route::get('action2',function(){
        return 2;
    });
});
//一组路由加统一前缀
Route::prefix('api')->group(function () {
    Route::get('/', function () {
        // 处理 /api 路由
    })->name('api.index');
    Route::get('users', function () {
        // 处理 /api/users 路由
    })->name('api.users');
});
//一组路由加统一命名前缀和统一前缀
// 路由命名+路径前缀
Route::name('user.')->prefix('user')->group(function () {
    Route::get('{id?}', function ($id = 1) {
        // 处理 /user/{id} 路由，路由命名为 user.show
        return route('user.show');
    })->name('show');
    Route::get('posts', function () {
        // 处理 /user/posts 路由，路由命名为 user.posts
    })->name('posts');
});
//------------------------------------路由进阶---------------------------
//-----路由模型绑定
//隐式绑定(路由参数必须和方法参数一致)，..默认传入值作为id去对应，若要自定义，可以再对应model中新增方法：
// public function getRouteKeyName() {
//     return 'name';  // 以任务名称作为路由模型绑定查询字段
// }
Route::get('task/{task}', function (\App\Models\Task $task) {
    dd($task); // 打印 $task 明细
});
//显式绑定(不推荐，详见手册)
//兜底路由，匹配不到路由时，给一个有好的自定义404提示
Route::fallback(function(){
    return '温馨提示：您已走丢';
});
//频率限制(提高安全性),1分钟不超过60次,否则返回429
Route::middleware('throttle:60,1')->group(function () {
    Route::get('/user', function () {
        //
    });
});
//csrf保护（跨站伪装请求保护）,为了安全起见，只要不是本站代码对路由的请求，只要涉及到“写”操作的路由，都会去验证一个token值，
//这个token值需要在form表单中设置，否则会报419
Route::delete('task/{id}', function ($id) {
    return 'Delete Task ' . $id;
})->name('task.delete');
//如果第三方回调，需要写入的路由，可以部分开放，去除CSRF校验，方法如下：
//通常这一些路由不放在web.php下，通常放在api.php下就可以。如果非要放在web.php下，在VerifyCsrfToken 中间件中添加如下代码：
/**
     * 从 CSRF 验证中排除的 URL
     *
     * @var array
     */
    // protected $except = [
    //     'alipay/*',
    //     'http://example.com/foo/bar',
    //     'http://example.com/foo/*',
    // ];
//返回多层级的路由,并传参
Route::get('multy-level-view',function(){
    return view('test.page1');
});
//----------------------------------------------------test--------------------------------------------
Route::get('/test/delaybind','TestController@delaybind');
Route::get('/test/useMyComposer','TestController@useMyComposer');
//-------------------------------------------redis-----------------------------------------------------
Route::get('/connection', function () {
    // dd(\Illuminate\Support\Facades\Redis::connection());
    // dd(app('redis')->connection());
    dd(app('redis.connection'));
});
Route::get('/site_visits', function () {
    return '网站全局访问量：' . \Illuminate\Support\Facades\Redis::get('site_total_visits');
});
Route::get('/stringGet/{value}','RedisController@stringGet');
Route::get('/stringSet/{key}/{value}','RedisController@stringSet');
Route::get('/incr/{key}','RedisController@incr');
Route::get('/queueSet/{listname}/{value}','RedisController@queueSet');
Route::get('/queueGet/{listname}','RedisController@queueGet');
Route::get('/listGetAll/{listname}','RedisController@listGetAll');
Route::get('/stackSet/{listname}/{value}','RedisController@stackSet');
Route::get('/stackGet/{listname}','RedisController@stackGet');
Route::get('/setSets/{setsname}/{value}','RedisController@setSets');
Route::get('/getSets/{setsname}','RedisController@getSets');
Route::get('/setSortedSets/{setsname}/{index}/{value}','RedisController@setSortedSets');
Route::get('/getSortedSets/{setsname}','RedisController@getSortedSets');
Route::get('/getReverseSortedSets/{setsname}','RedisController@getReverseSortedSets');
Route::get('/upSortedSetsMember/{setsname}/{value}','RedisController@upSortedSetsMember');

Route::get('/setHash/{hash}/{key}/{value}','RedisController@setHash');
Route::get('/getHash/{hash}/{key}','RedisController@getHash');

Route::get('/posts/popular', 'PostController@popular');
// Route::get('/posts/{post}', 'PostController@show');
Route::get('/posts/{id}', 'PostController@show')->where('id', '[0-9]+');














Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');
